<?php

namespace App\Http\Controllers\Applet\Sponsor;

use App\Services\Applet\Sponsor\SponsorGoodsService;
use Exception;
use Illuminate\Http\JsonResponse;

class SponsorGoodsController extends BaseSponsorController
{
    protected SponsorGoodsService $sponsorGoodsService;

    /**
     * @throws Exception
     */
    public function __construct()
    {
        parent::__construct();
        $this->sponsorGoodsService = $this->loadService('Applet\Sponsor\SponsorGoodsService');
    }

    /**
     * 商品列表
     * @return JsonResponse
     * @throws Exception
     */
    public function list(): JsonResponse
    {
        $list = $this->sponsorGoodsService->list($this->params);
        return outputJsonResult($list);
    }

    /**
     * 推荐商品列表
     * @return JsonResponse
     * @throws Exception
     */
    public function recommendList(): JsonResponse
    {
        $list = $this->sponsorGoodsService->recommendList();
        return outputJsonResult($list);
    }

    /**
     * 商品详情
     * @return JsonResponse
     * @throws Exception
     */
    public function detail(): JsonResponse
    {
        $rule = [
            'id' => 'required|integer|min:1'
        ];

        if ($this->ruleCheck($rule)) {
            return outputJsonError();
        }

        $data = $this->sponsorGoodsService->detail($this->params);
        return outputJsonResult($data);
    }

}
